<?php
	require("includes/database.php");

	$idBoletin = $_GET['idBoletin'];
	$codigoModelo = $_GET['codigoModelo'];
	$iOpcion = $_GET['iOpcion'];
	
	switch($iOpcion)
	{	
		case 1:
		{
			$sql = "SELECT concat(s.idsintoma, ' || ', s.codigo, ' - ' ,s.nombre, '%%') as sintoma, concat(f.idfalla, ' || ', f.codigo, ' - ' ,f.nombre, '%%') as falla, concat(a.idaccion, ' || ', a.codigo, ' - ' ,a.nombre, '%%') as accion, concat(p.idparte, ' || ', p.codigo, ' - ' ,p.descripcioninterna, '%%') as parte, concat(rxb.cantidad,'&&') as cantidad from sintomas s join reparacionesxboletin rxb on s.idsintoma = rxb.idsintoma join fallas f on rxb.idfalla = f.idfalla join acciones a on rxb.idaccion = a.idaccion join partes p on rxb.idparte = p.idparte WHERE idboletin = $idBoletin";
	
			$resultBoletines = readSQL($sql);
			$reparaciones='';
			foreach($resultBoletines as $valueBoletines)
			{
				$reparaciones = $reparaciones.$valueBoletines['sintoma'].$valueBoletines['falla'].$valueBoletines['accion'].$valueBoletines['parte'].$valueBoletines['cantidad'];
			}
			echo $reparaciones;
			break;
		}
		case 2:
		{
			$sql = "SELECT b.idboletin, numero, nombre, fecha FROM boletines b join modelosxboletin mxb on b.idboletin = mxb.idboletin join modelos m on mxb.idmodelo = m.idmodelo WHERE m.codigo = $codigoModelo GROUP BY b.idboletin";
			
			$resultBoletines = readSQL($sql);
			
			if(count($resultBoletines)>0)
			{
               	$boletines .= "<table width='100%' align='center'>";
			}
			
			foreach($resultBoletines as $valueBoletines)
			{
				$boletines .= "<tr>";
					$boletines .= "<td>";
						$boletines .= $valueBoletines['numero'];
					$boletines .= "</td>";
					$boletines .= "<td>";
						$boletines .= $valueBoletines['nombre'];
					$boletines .= "</td>";
					$boletines .= "<td>";
						$boletines .= $valueBoletines['fecha'];
					$boletines .= "</td>";
					$boletines .= "<td>";
						$boletines .= "<input type='button' value='Ver' onClick=\"verBoletin(".$valueBoletines['idboletin'].");\"";
					$boletines .= "</td>";
					$boletines .= "<td>";
						$boletines .= "<input type='button' value='Aplicar' onClick=\"aplicarBoletin(".$valueBoletines['idboletin'].");\"";
					$boletines .= "</td>";
				$boletines .= "</tr>";
			}
			
			if(count($resultBoletines)>0)
			{
				$boletines .= "</table>";
			}
			
			echo $boletines;
			break;	
		}
	}
	
?>